﻿@inject ContentService _contentService
@{

    var categoryId = ViewContext.RouteData.Values["categoryId"].To<int>(0);
    var mainCategories = await _contentService.GetCategoriesByParentAsync(0);
    var pageName = ViewContext.RouteData.Values["page"].ToString().ToLower();

}

<ul class="nav flex-column nav-pills">
    <li class="nav-item @if (pageName.Contains("index")) {<text>active</text> }">
        <a asp-page="/Index" class="nav-link ">首页</a>
    </li>
    @foreach (var item in mainCategories)
    {

        <li class="nav-item dropdown">
            <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">@item.Name</a>
            <div class="dropdown-menu">
                @foreach (var subItem in await _contentService.GetCategoriesByParentAsync(item.Id))
                {
                    <a class="dropdown-item @if (categoryId == subItem.Id) { <text>active</text>} " asp-page="/Content/Index" asp-route-categoryId="@subItem.Id">
                        @subItem.Name
                    </a>
                }
            </div>
        </li>
    }
</ul>
